package com.huatai.saas.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.common.controller.BaseController;
import com.huatai.saas.dto.OrderPageInfoListDto;
import com.huatai.saas.dto.SaveWorkingOrderDto;
import com.huatai.saas.dto.UpdateOrderForUserDto;
import com.huatai.saas.service.WorkingOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @program: nanming-saas
 * @description: 工单管理的控制器类
 * @author: zcw
 * @create: 2024-04-10
 */
@RestController
@Validated
@Slf4j
@Api(value = "工单管理", tags = "工单管理")
@RequestMapping("/order")
public class WorkingOrderController extends BaseController {

	@Autowired
	private WorkingOrderService workingOrderService;

	/**
	 * 用户新增工单
	 * @param workingOrderDto
	 * @return
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增工单", notes = "新增工单")
	//@PreAuthorize("hasAuthority('')")
	public R savaOrder(@Valid @RequestBody SaveWorkingOrderDto workingOrderDto){
		boolean result = workingOrderService.saveOrder(workingOrderDto);
		return R.status(result);
	}

	/**
	 * 查询用户自己的工单列表
	 * @param pageInfo
	 * @return
	 */
	@GetMapping("/getUserList")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "查询用户自己的工单列表", notes = "查询用户自己的工单列表")
	//@PreAuthorize("hasAuthority('')")
	public R getUserOrderList(OrderPageInfoListDto pageInfo){
		return R.data(workingOrderService.getUserWorkingOrderList(pageInfo));
	}

	/**
	 * 查询所有用户的工单列表
	 * @param pageInfo
	 * @return
	 */
	@GetMapping("/getAllList")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "查询所有用户的工单列表", notes = "查询所有用户的工单列表")
	//@PreAuthorize("hasAuthority('')")
	public R getAllOrderList(OrderPageInfoListDto pageInfo){
		return R.data(workingOrderService.getAllWorkingOrderList(pageInfo));
	}

	/**
	 * 删除工单
	 * @param id
	 * @return
	 */
	@PostMapping("/del/{id}")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "删除工单", notes = "删除工单")
	//@PreAuthorize("hasAuthority('')")
	public R delOrder(@PathVariable Long id){
		boolean result = workingOrderService.delOrder(id);
		return R.status(result);
	}

	/**
	 * 用户修改工单信息
	 * @param updateOrderForUserDto
	 * @return
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改工单信息", notes = "修改工单信息")
	//@PreAuthorize("hasAuthority('')")
	public R updateOrder(@Valid @RequestBody UpdateOrderForUserDto updateOrderForUserDto){
		boolean result = workingOrderService.updateOrder(updateOrderForUserDto);
		return R.status(result);
	}

	/**
	 * 处理工单信息，修改为未处理
	 * @param id 工单id
	 * @return
	 */
	@PostMapping("/set-untreated/{id}")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "修改工单状态信息为未处理", notes = "修改工单状态信息为未处理")
	public R setUntreated(@PathVariable Long id){
		return R.status(workingOrderService.setUntreated(id));
	}

	/**
	 * 处理工单信息，修改为处理中
	 * @param id 工单id
	 * @return
	 */
	@PostMapping("/set-handling/{id}")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "修改工单状态信息为处理中", notes = "修改工单状态信息为处理中")
	public R setHandling(@PathVariable Long id){
		return R.status(workingOrderService.setHandling(id));
	}

	/**
	 * 处理工单信息，修改为已处理
	 * @param id 工单id
	 * @return
	 */
	@PostMapping("/set-processed/{id}")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "修改工单状态信息为已处理", notes = "修改工单状态信息为已处理")
	public R setProcessed(@PathVariable Long id){
		return R.status(workingOrderService.setProcessed(id));
	}


}
